#include<iostream>
using namespace std;
<<<<<<< HEAD
int main()
{
	int n, m;
	int s=0;
	cin >> n >> m;
	for (int i = 2; i <= n; i++)
	{
		s = (s+m)%i;
	} 
	cout << s+1 << endl;
=======
int main(){
	int a[1000];
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		a[i] = 1;
	}
	int count = n;
	int num = 0;
	int k = -1;
	while (count != 1){
		k = (k+1)%n;
		if (a[k] == 1){
			num++;
		}
		if (num == m) {
			a[k] = 0;
			count--; 
			num = 0;
		} 
	}
	for (int i = 0; i < n; i++){
		if (a[i] == 1){
			cout << i+1;
			break;
		}
	}
>>>>>>> 21018dd9a1e3f7972ce1bca76e4e601a7100ece6
	return 0; 
} 
